﻿#pragma once
#include "AstType.h"
#include "SiContext.h"

class FunctionInstance;

class ClassInstanceType : public AstType, public MakeContext
{
	friend class AstClass;
public:
	bool singleton = false;
	SiContext* context = nullptr;
	ClassInstanceType* inherit = nullptr;	// 继承
	std::unordered_multimap<std::string, AstFunction*>			methds;		// 方法(有些方法可能是模版的，因此使用 AstFunction)
	std::unordered_map<std::string, Parameter>		members;		// 成员变量

	ClassInstanceType(const std::string& name);

	static bool isClass(AstType* tp) { 
		assert(tp);
		return dynamic_cast<ClassInstanceType*>(tp); 
	}
public:
	virtual std::string uniqueName();
	virtual llvm::Type* llvmType(llvm::LLVMContext& context);
	virtual SiContext* makeContext(SiContext *context, CodeGen* codeGen);
public:
	std::string _uname;
	static int serial;
public:
	llvm::StructType* _type = nullptr;
	std::map<std::string, FunctionInstance*> funcCache;
};
